package com.openxt.nbzj.fragment;

import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.openxt.nbzj.R;

/**
 * Created by 颖杰_2 on 2016/5/17.
 */
public class OpenxtBaseStyle implements View.OnClickListener {
    private Activity mContext;

    public interface OnBackActionListener {
        public void onBackAction();
    }

    protected OnBackActionListener listener = null;

    public OpenxtBaseStyle(Activity mContext, int viewId, String title) {
        this.mContext = mContext;
        mContext.setContentView(viewId);
        TextView tv = (TextView) mContext.findViewById(R.id.openxt_title);
        tv.setText(title);

        LinearLayout btn = (LinearLayout) mContext.findViewById(R.id.openxt_title_left);
        btn.setOnClickListener(this);
    }

    public void setTitle(String text){
        TextView tv = (TextView) mContext.findViewById(R.id.openxt_title);
        tv.setText(text);
    }

    public void setBackBtn(boolean has){
        LinearLayout btn = (LinearLayout) mContext.findViewById(R.id.openxt_title_left);
        if(has)
            btn.setVisibility(View.VISIBLE);
        else
            btn.setVisibility(View.GONE);
    }

    public LinearLayout getRight(){
        return (LinearLayout) mContext.findViewById(R.id.openxt_title_right);
    }

    public void setBackAction(OnBackActionListener listener){
        this.listener = listener;
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.openxt_title_left){
            if(listener != null)
                listener.onBackAction();
            else
                mContext.finish();
        }
    }
}
